# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p11.py
# @Time     : 2024/5/8 23:40
# @Author   : Robot-Zsj
"""
description:

字符串序列判定

https://fcqian.blog.csdn.net/article/details/127228559

i:
ace
abcde

o:
4

"""

s = input()
l = input()


def getResult():
    i = 0
    j = 0

    ans = -1

    while i < len(s) and j < len(l):
        if s[i] == l[j]:
            i += 1
            ans = j
        j += 1
    return ans


print(getResult())
